package com.zmy.xcx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmy.xcx.common.convention.exception.ClientException;
import com.zmy.xcx.common.enums.UserErrorCodeEnum;
import com.zmy.xcx.dao.entity.Patient;
import com.zmy.xcx.dao.mapper.PatientMapper;
import com.zmy.xcx.service.PatientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * 病人接口实现层
 */
@Slf4j
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Override
    public void createPatient(Patient patient) {
        this.save(patient);
    }

    @Override
    public Patient getPatient(String id) {
        LambdaQueryWrapper<Patient> queryWrapper = Wrappers.lambdaQuery(Patient.class)
                .eq(Patient::getId, id);
        Patient patient = baseMapper.selectOne(queryWrapper);
        if (patient == null) {
            throw new ClientException(UserErrorCodeEnum.USER_NULL);
        }
        return patient;
    }
}
